﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace TagBasedResourceManagePlatform.UI.Wpf
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        #region Dependency Properties

        public static readonly DependencyProperty SidebarWidthProperty = DependencyProperty.Register("SidebarWidth", typeof(int), typeof(MainWindow));
        public static readonly DependencyProperty TitleBarHeightProperty = DependencyProperty.Register("TitleBarHeight", typeof(int), typeof(MainWindow));

        #endregion

        #region Properties

        public int SidebarWidth
        {
            get { return (int)GetValue(SidebarWidthProperty); }
            set { SetValue(SidebarWidthProperty, value); }
        }

        public int TitleBarHeight
        {
            get { return (int)GetValue(TitleBarHeightProperty); }
            set { SetValue(TitleBarHeightProperty, value); }
        }

        #endregion

        #region Fields

        private Button _uiMainMenuButton;
        private Button _uiAddResourceButton;
        private ContextMenu _uiMainMenu;

        #endregion

        #region Private Functions

        private void InitializeEventHandler()
        {
            _uiMainMenuButton = (Button)this.Template.FindName("Part_MainMenu", this);
            _uiMainMenuButton.Click += UiMainMenuButton_Click;
            _uiMainMenuButton.MouseRightButtonUp += UiMainMenuButton_MouseRightButtonUp;
            _uiMainMenu = _uiMainMenuButton.ContextMenu;
            _uiMainMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
            _uiMainMenu.PlacementTarget = _uiMainMenuButton;

            _uiAddResourceButton = (Button)this.Template.FindName("Part_AddResource", this);
            _uiAddResourceButton.Click += UiAddResourceButton_Click;

        }

        #endregion

        #region Events Handler

        private void UiMainMenuButton_Click(object sender, RoutedEventArgs e)
        {
            _uiMainMenuButton.ContextMenu.IsOpen = true;
        }


        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            InitializeEventHandler();
        }


        private void UiAddResourceButton_Click(object sender, RoutedEventArgs e)
        {
            CreateResourceWindow crw = new CreateResourceWindow();
            crw.Owner = this;
            crw.ShowDialog();
        }

        private void UiMainMenuButton_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;
        }

        #endregion

        public MainWindow()
        {
            InitializeComponent();
            this.Loaded += MainWindow_Loaded;
        }
    }
}
